package com.ebt.m.proposal_v2.widget.dialog;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.WindowManager;

import com.ebt.m.proposal_v2.adapter.EBTRecyclerAdapter;
import com.ebt.m.view.RecyclerViewItemDivider;

/**
 * @author archer.qi
 *         Created on 2017/9/25.
 */
public class EBTBottomAdapterDialog<A extends EBTRecyclerAdapter> extends EBTBottomDialogBase {
    private RecyclerView mRecyclerView;
    private LinearLayoutManager mLinearLayoutManager;
    private A mAdapter;
    private String mTextTitle;

    @Override
    public void init() {
        initRecyclerView();
        hideBottom();
        addCloseButton();
        addDialogBody(mRecyclerView);
        bindRecyclerData();
    }

    @Override
    public void onResume() {
        super.onResume();
        resetDialogHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    }

    public EBTBottomAdapterDialog setAdapter(A adapter) {
        mAdapter = adapter;
        return this;
    }

    private void bindRecyclerData() {
        if (mAdapter != null) {
            mRecyclerView.setAdapter(mAdapter);
        }
    }

    private void initRecyclerView() {
        Context mContext = getActivity();
        mRecyclerView = new RecyclerView(mContext);
        mLinearLayoutManager = new LinearLayoutManager(mContext);
        mRecyclerView.setLayoutManager(mLinearLayoutManager);
        mRecyclerView.addItemDecoration(new RecyclerViewItemDivider(mContext, LinearLayoutManager.VERTICAL)
                .setAppearance(1, "#ffe2e2e2"));
    }

}
